<template>
	<view>
		<button @tap="pay">微信支付</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				openid: this.$store.getters.openid
			}
		},
		methods: {
			pay: function() {
				this.API.post("/wx/pay/" + this.openid).then(res => {
					console.log('res=>', res);
					
					if(res.data.code === 1200){
						
						let data = res.data.data;
						/* 
						 appId: "wxe4300736fa97589a"
						 nonceStr: "7SQk0vW8z0mhRoznBaCWK7RG5z8ofL3D"
						 openid: "o-B3q1fzZ_eK-wejsR0S_nIqCO-o"
						 order: "o-B3q1fzZ_eK-wejsR0S_nIqCO-o"
						 package: "prepay_id=wx18204358998962be187e99b71137210300"
						 prepay_id: "wx18204358998962be187e99b71137210300"
						 sign: "E9DDC617F7D9F9151ABF205B1E4D7DB2"
						 signType: "MD5"
						 timeStamp: "1571402639"
						 */
						uni.requestPayment({
						    provider: 'wxpay',
						    timeStamp: data.timeStamp,
						    nonceStr: data.nonceStr,
						    package: data.package,
						    signType: 'MD5',
						    paySign: data.sign,
						    success: function (res) {
						        console.log('success:' + JSON.stringify(res));
						    },
						    fail: function (err) {
						        console.log('fail:' + JSON.stringify(err));
						    }
						});
					}
					
					
					
					
				}).catch(error => {
					console.log("error");
				})
			}
		}
	}
</script>

<style>

</style>
